# -- coding: utf-8 --

import pyperclip as clp
import str_operate
# 判断输出是否正确


if __name__ == '__main__':
    # 第一行是120个数字(1~49)
    #
    lines = clp.paste().split('\n')
    if len(lines) < 120*80:
        # print("")
        exit("复制的行数不够120x80行。")
    # 取出第一行并分割
    # 确认这120个数字在1~49之间
    cmp = input('请输入一个1~49之间的数字：')
    if not str_operate.inputIsOK(cmp):
        # print("输入的内容不是1~49之间的数字。")
        exit("输入的内容不是1~49之间的数字。")
    else:
        cmp = '{:0>2}'.format(cmp)

        lst = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
               0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
               0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
               0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
               0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        result = ""
        lineNO = 0

        # 外循环loop['extrinsic']（120）次
        loop = {'extrinsic': 120, 'internal': 80}
        for x in range(0, loop['extrinsic']):
            # 将数组lst的各值置零
            for item in lst:
                item = 0

            # 内循环loop['internal']（80）次
            for y in range(0, loop['internal']):
                # 取出一行分解成组
                s = str_operate.splitString(lines[lineNO], '[ \t\r\n]+')
                lineNO += 1

                # 从数组中找出1~49的次数记录在lst中
                for key in range(1, 50):
                    lst[key] += str_operate.time(s, "{:0>2}".format(key))

            pos = 0
            iCmp = lst[int(cmp)]
            for key in range(1, 50):
                if lst[key] > iCmp or (lst[key] == iCmp and key < int(cmp)):
                    pos += 1

            ''''''
            d = dict()
            for x, y in d.items():
                if y > d[cmp] or (y == d[cmp] and x <= cmp):
                    pos += 1
            ''''''

            result += "{}\n".format(pos)
        clp.copy(result)
